<?php

    #-------------------------------------------------------------#
	# This file is part of the Tekuna MVC Microframework for PHP. #
	# (c) 2009 Niels Jäckel <niels.jaeckel@tekuna.org>            #
	# Please visit http://tekuna.org/ for more information.       #
	#                                                             #
	# This software is licensed under the MIT License. Please     #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#


	/**
	 * URL Information object. It holds the full URL that was requested,
	 * the base URL of the active module, the component URL and the matched
	 * dynamic parts of the component URL. Example:
	 *
	 * full URL:        /module/section/file.html
	 * module base URL: /module/
	 * component URL:   section/file.html
	 * parts for pattern * / *.html
	 *   part 1: section
	 *   part 2: file
	 */

	class URLInformation {

		protected
			$sRequestURL = '',
			$sModuleBaseURL = '',
			$sComponentURL = '',
			$arrMatchedURLParts = array();


		/**
		 * Set the request URL
		 *
		 * @param string $sRequestURL
		 */

		public function setRequestURL($sRequestURL) {

			$this -> sRequestURL = $sRequestURL;
		}


		/**
		 * @return string Returns the current request URL
		 */

		public function getRequestURL() {

			return $this -> sRequestURL;
		}


		/**
		 * According to the current request URL, this method returns the relative path that
		 * points to the web-root of the application. This relative path should be used as
		 * prefix to point to other pages or other resources (CSS, JavaScript) of the application.
		 *
		 * Examples:
		 *    request URL = /foo/bar/baz.html
		 *    relative base path = ../../
		 *
		 *    request URL = /index.html
		 *    relative base path =        (the empty strig)
		 *
 		 * @return the relative base path
		 */
		public function getRelativeBasePath() {

			// extract the path (if there is a document given or not)
			$sParts = preg_split('~/~', $this -> sRequestURL);

			// return the empty string if we are in the root
			if (count($sParts) <= 2) {

				return '';
			}

			// put ../ for every path depth
			return str_repeat('../', count($sParts) - 2);
		}


		/**
		 * Set the module base URL
		 *
		 * @param string $sModuleBaseURL
		 */

		public function setModuleBaseURL($sModuleBaseURL) {

			$this -> sModuleBaseURL = $sModuleBaseURL;
		}


		/**
		 * @return string Returns the current module base URL
		 */

		public function getModuleBaseURL() {

			return $this -> sModuleBaseURL;
		}


		/**
		 * Set the component URL
		 *
		 * @param string $sComponentURL
		 */

		public function setComponentURL($sComponentURL) {

			$this -> sComponentURL = $sComponentURL;
		}


		/**
		 * @return string Returns the current component URL
		 */

		public function getComponentURL() {

			return $this -> sComponentURL;
		}


		/**
		 * Set the matched URL parts
		 *
		 * @param array $arrMatchedURLParts
		 */

		public function setMatchedURLParts(array $arrMatchedURLParts) {

			$this -> arrMatchedURLParts = $arrMatchedURLParts;
		}


		/**
		 * @return array Returns the current matched URL parts
		 */

		public function getMatchedURLParts() {

			return $this -> arrMatchedURLParts;
		}
	}


